package com.itheima.controller;

import com.github.pagehelper.Page;
import com.itheima.domain.Book;
import com.itheima.domain.End;
import com.itheima.domain.Statistics;
import com.itheima.mapper.BookMapper;
import com.itheima.service.BookService;
import com.itheima.service.ListRankingService;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户登录和注销Controller
 */
@Controller
@RequestMapping("/shower")
public class ListRankingController {


    //这个要在ListRanking里面注解@Service@Transactional
    @Autowired
    private ListRankingService listRankingService;
    @Autowired
    private BookService bookService;


    /*
   用户登录
    */

    @RequestMapping("/detail")
    public   ModelAndView detail(HttpServletRequest request)
    {
System.out.println("查看详情的id是:"+request.getParameter("getid"));
        System.out.println("查看详情的src是:"+request.getParameter("getsrc"));
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("showdetail");
        PageResult pageResult1=bookService.selectallbook();
        System.out.println(pageResult1.getRows().size()+"长度在此1");
        modelAndView.addObject("pageResult1", pageResult1);
        modelAndView.addObject("getid",request.getParameter("getid"));
        modelAndView.addObject("getsrc",request.getParameter("getsrc"));
        return modelAndView;

    }

@RequestMapping("/gst")
public    ModelAndView gstisgood()
{
    End end1 = new End();
    Statistics statistics=new Statistics();


    PageResult gstend = listRankingService.showall(end1, 1,10, "end");
    PageResult gsthumanqi = listRankingService.showall(end1, 1,10, "humanqi");
    PageResult gstnew = listRankingService.showall(end1, 1,10, "new");
    PageResult gstpraise = listRankingService.showall(end1, 1,10,"praise");
    PageResult gstrecommend = listRankingService.showall(end1, 1,10, "recommend");
    PageResult gststoreup = listRankingService.showall(end1, 1,10, "storeup");
    PageResult gsttopsearch= listRankingService.showall(end1, 1,10, "topsearch");
    PageResult gststatistics = listRankingService.showstatistics(statistics, 1,10);
    PageResult data=bookService.selectallbook();

    System.out.println("长度为"+gstend.getRows().size());

    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("gst1");
    modelAndView.addObject("gstend", gstend);
    modelAndView.addObject("gsthumanqi", gsthumanqi);
    modelAndView.addObject("gstnew", gstnew);
    modelAndView.addObject("gstpraise", gstpraise);
    modelAndView.addObject("gstrecommend", gstrecommend);
    modelAndView.addObject("gststoreup", gststoreup);
    modelAndView.addObject("gsttopsearch", gsttopsearch);
    modelAndView.addObject("gststatistics", gststatistics);
    modelAndView.addObject("data", data);

  return modelAndView;

}

    @RequestMapping("/showall")
    public ModelAndView showall(String nature, HttpServletRequest request, Integer pageNum, Integer pageSize) {
        System.out.println(nature);
        End end1 = new End();
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 10;
        }
       PageResult pageResult = listRankingService.showall(end1, pageNum, pageSize, nature);
        PageResult pageResult1=bookService.selectallbook();


        int i;
//      System.out.println("存在"+pageResult.getRows().size());

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("showall");
        modelAndView.addObject("pageResult", pageResult);
        modelAndView.addObject("pageResult1", pageResult1);
        modelAndView.addObject("pageNum", pageNum);
        modelAndView.addObject("nature1",nature);
        modelAndView.addObject("gourl", "/user/search");
        return modelAndView;

    }


@RequestMapping("showstatistics")
public ModelAndView showstatistics(HttpServletRequest request, Integer pageNum, Integer pageSize) {

    Statistics statistics=new Statistics();
        if (pageNum == null) {
        pageNum = 1;
        }
        if (pageSize == null) {
        pageSize = 10;
        }
        PageResult pageResult = listRankingService.showstatistics(statistics, pageNum, pageSize);
        System.out.println("存在"+pageResult.getRows().size());
        ModelAndView modelAndView = new ModelAndView();
       modelAndView.addObject("pageResult", pageResult);
        modelAndView.setViewName("showstatistics");
        return modelAndView;
        }
        }


